package com.core.zyyz.pcmc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.core.zyyz.pcmc.domain.PcmcOrg;
import com.core.zyyz.pcmc.service.PcmcOrgService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.common.utils.poi.ExcelUtil;
import com.core.common.core.page.TableDataInfo;

/**
 * 组织架构Controller
 *
 * @author core
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/pcmc/org")
public class PcmcOrgController extends BaseController
{
    @Autowired
    private PcmcOrgService pcmcOrgService;

    /**
     * 查询组织架构列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:org:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcmcOrg pcmcOrg)
    {
        //startPage();
        List<PcmcOrg> list = pcmcOrgService.selectPcmcOrgList(pcmcOrg);
        return getDataTable(list);
    }

    /**
     * 导出组织架构列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:org:export')")
    @Log(title = "组织架构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcmcOrg pcmcOrg)
    {
        List<PcmcOrg> list = pcmcOrgService.selectPcmcOrgList(pcmcOrg);
        ExcelUtil<PcmcOrg> util = new ExcelUtil<PcmcOrg>(PcmcOrg.class);
        util.exportExcel(response, list, "组织架构数据");
    }

    /**
     * 获取组织架构详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcmc:org:query')")
    @GetMapping(value = "/{orgCode}")
    public AjaxResult getInfo(@PathVariable("orgCode") String orgCode)
    {
        return success(pcmcOrgService.selectPcmcOrgByOrgCode(orgCode));
    }

    /**
     * 新增组织架构
     */
    @PreAuthorize("@ss.hasPermi('pcmc:org:add')")
    @Log(title = "组织架构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcmcOrg pcmcOrg)
    {
        return toAjax(pcmcOrgService.insertPcmcOrg(pcmcOrg));
    }

    /**
     * 修改组织架构
     */
    @PreAuthorize("@ss.hasPermi('pcmc:org:edit')")
    @Log(title = "组织架构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcmcOrg pcmcOrg)
    {
        return toAjax(pcmcOrgService.updatePcmcOrg(pcmcOrg));
    }

    /**
     * 删除组织架构
     */
    @PreAuthorize("@ss.hasPermi('pcmc:org:remove')")
    @Log(title = "组织架构", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orgCodes}")
    public AjaxResult remove(@PathVariable String[] orgCodes)
    {
        return toAjax(pcmcOrgService.deletePcmcOrgByOrgCodes(orgCodes));
    }
}
